package com.base.starter.config;

import org.springframework.boot.web.servlet.filter.OrderedFilter;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @Description: 自定义跨域配置
 * CorsFilter是用于跨域资源共享的过滤器
 * OrderedFilter是自定义接口，用于在Spring框架中定义过滤器的顺序
* @Param:
* @return:
* @Author: zhou minghao
* @Date: 10:27 2024/4/18
*/ 
public class CustomCorsFilter extends CorsFilter implements OrderedFilter {
    public CustomCorsFilter(CorsConfigurationSource configSource) {
        super(configSource);
    }

    @Override
    public int getOrder() {
        return -100;
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        //设置跨域
        super.doFilterInternal(request, response, filterChain);
    }
}
